;;; $Id: chibi-simple-fcgi-call-main.scm 195 2013-07-17 00:03:33Z
;;; alan.watson.f $

(define (call-main input-string)
  (parameterize ((current-input-port (open-input-string input-string))
                 (current-output-port (open-output-string))
                 (current-error-port (open-output-string)))
    (when (equal? "GET" (get-environment-variable "QUERY_METHOD"))
      (close-input-port (current-input-port)))
    (call-with-current-continuation
     (lambda (k)
       (with-exception-handler
           (lambda (e)
             (display "An exception was raised in (main): " (current-error-port))
             (write e (current-error-port))
             (newline (current-error-port))
             (k))
         main)))
    (cons (get-output-string (current-output-port))
          (get-output-string (current-error-port)))))
